<?
/*
Bitsand - a web-based booking system for LRP events
Copyright (C) 2006, 2007 Russell Peter Phillips

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

include ('inc_head_db.php');
include ('inc_admin.php');
include ('inc_head_html.php');

$key = CRYPT_KEY;
//Create query
$sql = "SELECT plPlayerID, AES_DECRYPT(plEmail, '$key') AS dEmail, bkPlayerID, bkDateOOCConfirmed, bkDateICConfirmed, bkDatePaymentConfirmed " .
	"FROM players, bookings WHERE plPlayerID = bkPlayerID ";
if ($_POST ['rdoPeople'] == 1)
	$sql .= "AND bkDatePaymentConfirmed <> '0000-00-00' AND bkDatePaymentConfirmed <> ''";
elseif ($_POST ['rdoPeople'] == 2)
	$sql .= "AND (bkDateOOCConfirmed <> '0000-00-00' AND bkDateOOCConfirmed <> '' AND bkDateICConfirmed <> '0000-00-00' AND bkDateICConfirmed <> '') AND (bkDatePaymentConfirmed = '0000-00-00' OR bkDatePaymentConfirmed = '')";
elseif ($_POST ['rdoPeople'] == 3)
	$sql .= "AND ((bkDateOOCConfirmed <> '0000-00-00' AND bkDateOOCConfirmed <> '') OR (bkDateICConfirmed <> '0000-00-00' AND bkDateICConfirmed <> '')) AND (bkDatePaymentConfirmed = '0000-00-00' OR bkDatePaymentConfirmed = '')";
else
	$sql = '';

if ($sql != '') {
	$result = mysqli_query ($link, $sql);
	while ($row = mysqli_fetch_assoc ($result))
		echo $row ['dEmail'] . "<br>\n";
}
?>

<h1><?=TITLE?> - E-mailer</h1>

<p>
<a href = 'admin.php'>Admin</a>
</p>

<p>
This page can be used to send an e-mail to a sub-set of the people in the system.
</p>

<form action = 'admin_mailer.php' method = 'post'>
<p>
Select a group of people to send to:<br>
<label><input type = "radio" name = "rdoPeople" value = "1">OOC <b>AND</b> IC details confirmed, <b>have</b> paid</label><br>
<label><input type = "radio" name = "rdoPeople" value = "2">OOC <b>AND</b> IC details confirmed, <b>have not</b> paid</label><br>
<label><input type = "radio" name = "rdoPeople" value = "3">OOC <b>OR</b> IC details confirmed (not both)</label><br>
</p>

<table>
<tr>
<td>Subject:</td>
<td><input type = "text" name = "txtSubject" size = "40"></td>
</tr>
<tr><td colspan = "2">&nbsp;</td></tr>
<tr>
<td>Message text:</td>
<td><textarea name = "txtBody" cols = "100" rows = "12"></textarea></td>
</tr>
<tr><td colspan = "2">&nbsp;</td></tr>
<tr>
<td class = "mid"><input type = "reset"></td>
<td class = "mid"><input type = "submit" value = "Send" name = "btnSubmit"></td>
</tr>

</table>
</form>

<?
include ('inc_foot.php');
?>
